package com.atqh.logistics.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration //配置类
@EnableSwagger2// 开启Swagger2的自动配置
public class SwaggerConfig {

    //配置多个分组
/*
    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("group1");
    }
 
    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("group2");
    }
*/
    @Bean
    public Docket webApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(apiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket customApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("customApi")
                .apiInfo(customApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/custom/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket managerApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("managerApi")
                .apiInfo(managerApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/manager/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket userApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("driverApi")
                .apiInfo(driverApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/driver/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket noticeApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("noticeApi")
                .apiInfo(noticeApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/notice/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket requestApiConfig() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("requestApi")
                .apiInfo(requestApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/request/.*")))
                .build();
        return docket;
    }

    private ApiInfo apiInfo() {
//配置文档信息
        Contact contact = new Contact("阿哲", "2033244875@qq.com", "2033244875@qq.com");
        return new ApiInfo(
                "物流公司运营管理系统后端接口文档Swagger", // 标题
                "物流公司运营管理系统后端接口", // 描述
                "v1.0", // 版本
                "2033244875@qq.com", // 组织链接
                contact, // 联系人信息
                "Apach 2.0 许可", // 许可
                "许可链接", // 许可连接
                new ArrayList<>()// 扩展
        );
    }

    private ApiInfo customApiInfo() {
        return new ApiInfoBuilder().title("用户功能的API文档")
                .description("本文描述了客户功能的api接口定义")
                .version("1.0")
                .contact(new Contact("大叔azhe", "", "2033244875@qq.com"))
                .build();
    }

    private ApiInfo managerApiInfo() {
        return new ApiInfoBuilder().title("管理员功能的API文档")
                .description("本文描述了管理员功能的api接口定义")
                .version("1.0")
                .contact(new Contact("大叔azhe", "", "2033244875@qq.com"))
                .build();
    }

    private ApiInfo driverApiInfo() {
        return new ApiInfoBuilder().title("司机功能的API文档")
                .description("本文描述了司机功能的api接口定义")
                .version("1.0")
                .contact(new Contact("大叔azhe", "", "2033244875@qq.com"))
                .build();
    }

    private ApiInfo requestApiInfo() {
        return new ApiInfoBuilder().title("申请功能的API文档")
                .description("本文描述了申请功能的api接口定义")
                .version("1.0")
                .contact(new Contact("大叔azhe", "", "2033244875@qq.com"))
                .build();
    }

    private ApiInfo noticeApiInfo() {
        return new ApiInfoBuilder().title("公告功能的API文档")
                .description("本文描述了公告功能的api接口定义")
                .version("1.0")
                .contact(new Contact("大叔azhe", "", "2033244875@qq.com"))
                .build();
    }


}